//
//  ViewController.m
//  BAPopView
//
//  Created by boai on 2017/8/2.
//  Copyright © 2017年 boai. All rights reserved.
//

#import "ViewController.h"
#import "SSPopupView.h"
#import "ViewController2.h"

#define kWidth [UIScreen mainScreen].bounds.size.width
#define kHeight [UIScreen mainScreen].bounds.size.height


static NSString * const kCellID = @"cell";
@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>

@property(nonatomic, strong) UITableView *tableView;
@property (strong, nonatomic) SSPopupView *popView;
@property(nonatomic, strong) NSArray *dataArray;

@end

@implementation ViewController

#pragma mark - LifeCycle

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"popView";
    self.tableView.hidden = NO;
    
    // test view
    UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidth, 100)];
    testView.backgroundColor = [UIColor orangeColor];
    
    // init pop
    _popView = [SSPopupView popupWithContentView:testView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
    
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kCellID];
    }
    cell.textLabel.text = self.dataArray[indexPath.row];
    
    return cell;
    
}

#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    switch (indexPath.row) {
        case 0: {
            [self clearAction];
            [_popView showWithLayout:SSPopupLayoutCenter];
        }
            break;
        case 1: {
            [self fadeAction];
            [_popView showWithLayout:SSPopupLayoutMake(SSPopupHorizontalLayoutCenter, SSPopupVerticalLayoutBottom)];
        }
            break;
        case 2: {
            _popView.showType = SSPopupShowTypeSlideInFromLeft;
            _popView.dismissType = SSPopupDismissTypeSlideOutToLeft;
            [_popView showWithLayout:SSPopupLayoutCenter];
        }
            break;
        case 3:
        {
            [self.navigationController pushViewController:[ViewController2 new] animated:YES];
        }
            break;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}

#pragma mark - Private

- (void)clearAction {
    _popView.showType = SSPopupShowTypeNone;
    _popView.dismissType = SSPopupDismissTypeNone;
}

- (void)fadeAction {
    _popView.showType = SSPopupShowTypeFadeIn;
    _popView.dismissType = SSPopupDismissTypeFadeOut;
}

- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];

        _tableView.dataSource = self;
        _tableView.delegate = self;
        
        [self.view addSubview:_tableView];
    }
    return _tableView;
}

- (NSArray *)dataArray
{
    if (!_dataArray)
    {
        _dataArray = @[
                       @"快捷居中",
                       @"自定义布局",
                       @"动画",
                       @"test"
                       ];
    }
    return _dataArray;
}



@end
